package com.work.cos.web.controller.api;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.work.cos.domain.vo.ComServiceResVo;
import com.work.cos.service.interfc.msg.IMsgMessageService;
import com.work.cos.service.interfc.msg.IMsgTypeService;

@RestController
@RequestMapping("/api/msg")
public class MessageController {
	
private static Logger LOGGER = LoggerFactory.getLogger(MessageController.class);
	
	@Autowired
	private IMsgTypeService typeService;
	@Autowired 
	private IMsgMessageService messageService;

	/**
	 * 查询消息类型列表
	 * @return
	 */
	@PostMapping(value = "/types")
	public ComServiceResVo queryTypes(){
		LOGGER.debug("query msg types ... ");
		return ComServiceResVo.returnList(typeService.getAll());
	}
	
	/**
	 * 查询相关类型的消息列表
	 * @return
	 */
	@PostMapping(value = "/messages")
	public ComServiceResVo queryMessages(@RequestParam Long typeId){
		LOGGER.debug("query msg  ... ");
		return ComServiceResVo.returnList(messageService.getMessagesByTypeIdAndIsDel(typeId, 0));
	}
	
	/**
	 * 查询消息详情
	 * @return
	 */
	@PostMapping(value = "/message")
	public ComServiceResVo queryMessage(@RequestParam Long id){
		LOGGER.debug("query msg detail ... ");
		return ComServiceResVo.returnEntity(messageService.getOneByIdAndIsDel(id, 0));
	}

}
